package com.dao.impl;

import java.util.List;

import com.util.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.dao.AutomaticInterventionDAO;
import com.rev.Automaticintervention;
import com.rev.AutomaticinterventionHome;
import com.rev.Message;
import com.rev.MessageHome;
import com.rev.SourceHome;
import com.rev.Sourcetype;
import com.rev.SourcetypeHome;

public class AutomaticInterventionDAOImpl implements AutomaticInterventionDAO{
	private AutomaticinterventionHome aih = new AutomaticinterventionHome(); 

	public boolean insert(Automaticintervention automaticIntervention) {
		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			Transaction  transaction = session.beginTransaction();
			aih.attachDirty(automaticIntervention);
			transaction.commit();
			session.close();
			return true;
		} catch (Exception e) {}
		return false;
	}

	public boolean update(Automaticintervention automaticIntervention) {
		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			Transaction  transaction = session.beginTransaction();
			aih.attachDirty(automaticIntervention);
			transaction.commit();
			session.close();
			return true;
		} catch (Exception e) {
		}
		return false;
	}

	public boolean delete(Automaticintervention automaticIntervention) {
		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			Transaction  transaction = session.beginTransaction();
			aih.delete(automaticIntervention);
			transaction.commit();
			session.close();
			return true;
		} catch (Exception e) {
		}
		return false;
	}

	public List<Automaticintervention> findAll() {

		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			session.beginTransaction();
			List list = aih.findByExample(new Automaticintervention());
			session.getTransaction().commit();
			session.close();
			return list;
		} catch (Exception e) {
		}
		return null;
	}

	public Automaticintervention findById(int id) {
		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			session.beginTransaction();
			Automaticintervention s = aih.findById(id);
			session.getTransaction().commit();
			session.close();
			return s;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return null;
	}
}
